/*
* @Author: root
* @Date:   2017-11-05 13:34:13
* @Last Modified by:   root
* @Last Modified time: 2017-11-26 18:10:44
*/
'use strict'
require('./index.css');

var _util     = require('util/util.js');
 
// 通用页面头部
var header = {
    init 	  : function(){
        this.onload();
        this.bindEvent();
    },
    //数据回填
    onload    : function(){
    	var keyword = _util.getUrlParam('keyword');
    	//数据存在则回填数据
    	if (keyword) {
    		$('#search-input').val(keyword);	
    	}
    	//如果keyword为空则直接返回首页
    	
    }
    ,
    //点击事件
    bindEvent  : function(){
    	//点击搜索按钮以后，做搜索提交
    	var _this = this;
      $("#search-btn").click(function(){
      	_this.seachSumit();
      });
      //输入回车后做提交
      $("#search-input").keyup(function(e){
      	if (e.keyCode) {
      		//判断是否是回车
      		if (e.keyCode===13) {
      			_this.searchSubmit();
      		}
      	}
      });
    },
    //搜索的提交
    seachSumit : function(){
    	var keyword = $.trim($('#search-input').val());
    	if(keyword!==''){
	window.location.href = './list.html?keyword='+keyword+'';
    		
    	}else{
	window.location.href ='#';
	}
     }
};


header.init();
